package cn.homework03;

import java.util.Scanner;

public class Goods {
    public String[] goods = new String[]{"电风扇", "洗衣机", "电视机", "冰箱", "空调机"};
    public double[] price = new double[]{124.23, 4500.0, 8800.9, 5000.88, 4456.0};
    Scanner input = new Scanner(System.in);
    /**
     * 判断用户名密码是否正确
     */
    boolean flag = false;
    /**
     * 初始用户名和密码
     */
    public String nameString = "zpf", passString = "123";

    /**
     * 登陆方法
     *
     * @return
     */
    public boolean login() {
        System.out.print("请输入用户名:");
        String name = input.next();
        System.out.print("请输入密码:");
        String pass = input.next();
        if (name.equals(nameString) && pass.equals(passString)) {
            System.out.println("登陆成功!");
            flag = true;
        } else {
            System.out.println("用户名或密码输入错误");
        }
        return flag;
    }

    /**
     * 显示价目表方法
     */
    public void show() {
        for (int i = 0; i < 5; i++) {
            System.out.println("\t" + (i + 1) + "\t" + goods[i] + "\t" + price[i]);
        }

    }

    /**
     * 格式化输出信息
     *
     * @return str
     */
    public StringBuffer change(double d) {
        StringBuffer str = new StringBuffer(String.valueOf(d));
        for (int i = str.indexOf(".") - 3; i > 0; i = i - 3) {
            str.insert(i, ',');
        }
        return str;
    }

}

